function firstCharUpper(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}

export function HandlePostData(responseList) {
    let statusList = [];
    for (let i = 0; i < responseList.length; i++) {
        statusList.push(responseList[i].Record);
    }

    if(statusList.length < 0) return;
    const arrFirst = statusList[0];
    let keys = [];
    for (let key in arrFirst) {
        keys.push(key)
    }
    let length = statusList.length;
    let obj = {
        length: 0,
        data: {}
    };
    obj.length = length;
    for (let i = 0; i < keys.length; i++) {
        obj.data[keys[i]] = {
            key: keys[i],
            list:[],
        }
    }
    for (let i = 0; i <statusList.length ; i++) {
        const tem = statusList[i];
        for (let j in tem) {
            obj.data[j].list.push(tem[j])
        }
    }
    return obj;
}

export function handleEditData(values, key, id) {
    const data = values.data;
    let index = 0;
    let inputValue = {}
    for (let i in data) {
        if (i.toLowerCase() === key.toLowerCase()) {
            const arr = data[i].list
            for (let j = 0; j < arr.length; j++) {
                if(arr[j] === id){
                    index = j;
                }
            }
        }
    }
    for (let i in data) {
        inputValue[firstCharUpper(i)] = data[i].list[index];
    }
    let editAttributes = [];
    for (let i in data) {
        let tem = {}
        tem.key = firstCharUpper(i);
        tem.value = i;
        editAttributes.push(tem)
    }
    return {inputValue, editAttributes};
}